package cn.acac.yygh.sms.listener;

import cn.acac.yygh.mq.MqConst;
import cn.acac.yygh.sms.service.SMSService;
import cn.acac.yygh.vo.msm.MsmVo;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SmsListener {

    @Autowired
    private SMSService smsService;

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = MqConst.QUEUE_MSM_ITEM,durable = "true"),
                    exchange = @Exchange(name = MqConst.EXCHANGE_DIRECT_MSM),
                    key = MqConst.ROUTING_MSM_ITEM
            )
    })
    public void consumer(MsmVo msmVo, Message message, Channel channel){
        // 调用业务发送短信
        smsService.sendSms(msmVo);
    }
}
